import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  },
 
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

// router.beforeEach((to, from, next) => {
//   console.log(window.localStorage.getItem("Token") )
// // to: Route: 即将要进入的目标 路由对象
// // from: Route: 当前导航正要离开的路由
// // next: Function: 一定要调用该方法来 resolve 这个钩子。执行效果依赖 next 方法的调用参数。
//   const route = ['index', 'list'];
//   let isLogin = window.localStorage.getItem("Token") ; // 是否登录
// // 未登录状态；当路由到route指定页时，跳转至login
//   if (route.indexOf(to.name) >= 0) {
//     if (isLogin == null) {
//       this.$router.push({'path':'/Login/'})
//     }
//   }
// // 已登录状态；当路由到login时，跳转至home
//
//   localStorage.setItem('routerName', to.name)
//   if (to.name === 'login') {
//     if (isLogin != null) {
//       this.$router.push({'path':'/Home/'})
//     }
//   }
//   next();
// });



export default router
